local love = require("love")
local pacman, food

function love.load()
    love.graphics.setBackgroundColor(0.1, 0.3, 0.7)

    pacman = {
        x = 200,
        y = 200,
        mouth_width = math.pi / 3,
        rotate_angle = 0,
    }
    food = {
        x = 500,
        y = 200,
        eaten = false,
    }
end

function love.update(dt)
    -- move
    if love.keyboard.isDown("a") then pacman.x = pacman.x - 1 end
    if love.keyboard.isDown("d") then pacman.x = pacman.x + 1 end
    if love.keyboard.isDown("s") then pacman.y = pacman.y + 1 end
    if love.keyboard.isDown("w") then pacman.y = pacman.y - 1 end

    -- rotate
    if love.keyboard.isDown("down") then 
        pacman.rotate_angle = pacman.rotate_angle + dt
    elseif love.keyboard.isDown("up") then
        pacman.rotate_angle = pacman.rotate_angle - dt
    end

    if pacman.x >= food.x + 20 then
        food.eaten = true
    end
end

function love.draw()
    if not food.eaten then
        love.graphics.setColor(0, 0, 0)
        love.graphics.rectangle("fill", food.x, food.y, 100, 100)
    end

    love.graphics.setColor(0.7, 0.7, 1)
    love.graphics.arc("fill", pacman.x, pacman.y, 60, 
            pacman.mouth_width / 2 + pacman.rotate_angle, 
            2 * math.pi - pacman.mouth_width / 2 + pacman.rotate_angle)
end
